package com.hemerasolutions.v2trainer.model.exercise;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.ManyToOne;

import com.hemerasolutions.v2trainer.model.base.BaseModel;
import com.hemerasolutions.v2trainer.model.muscle.Muscle;

@Entity
public class ExerciseMuscle extends BaseModel {
	 
	private static final long serialVersionUID = 1L;
	
    @Column
    private boolean primaryMuscle;
    
    @ManyToOne
    private Exercise exercise;
    
    @ManyToOne
    private Muscle muscle;
    

	public ExerciseMuscle() {
		super();
		this.id = null;
	}

	public ExerciseMuscle(boolean primaryMuscle, Exercise exercise,
			Muscle muscle) {
		super();
		this.primaryMuscle = primaryMuscle;
		this.exercise = exercise;
		this.muscle = muscle;
	}

	public ExerciseMuscle(ExerciseMuscle other, Exercise exercise) {
		this();
		this.primaryMuscle = other.primaryMuscle;
		this.muscle = other.muscle;
		this.exercise = exercise;
	}


	public boolean isPrimaryMuscle() {
		return primaryMuscle;
	}

	public void setPrimaryMuscle(boolean primaryMuscle) {
		this.primaryMuscle = primaryMuscle;
	}

	public Exercise getExercise() {
		return exercise;
	}

	public void setExercise(Exercise exercise) {
		this.exercise = exercise;
	}

	public Muscle getMuscle() {
		return muscle;
	}

	public void setMuscle(Muscle muscle) {
		this.muscle = muscle;
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#hashCode()
	 */
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((exercise == null) ? 0 : exercise.hashCode());
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		result = prime * result + ((muscle == null) ? 0 : muscle.hashCode());
		result = prime * result + (primaryMuscle ? 1231 : 1237);
		return result;
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#equals(java.lang.Object)
	 */
	@Override
	public boolean equals(Object obj) {
		if (this == obj) {
			return true;
		}
		if (obj == null) {
			return false;
		}
		if (getClass() != obj.getClass()) {
			return false;
		}
		ExerciseMuscle other = (ExerciseMuscle) obj;
		if (exercise == null) {
			if (other.exercise != null) {
				return false;
			}
		} else if (!exercise.equals(other.exercise)) {
			return false;
		}
		if (id == null) {
			if (other.id != null) {
				return false;
			}
		} else if (!id.equals(other.id)) {
			return false;
		}
		if (muscle == null) {
			if (other.muscle != null) {
				return false;
			}
		} else if (!muscle.equals(other.muscle)) {
			return false;
		}
		if (primaryMuscle != other.primaryMuscle) {
			return false;
		}
		return true;
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString() {
		return "ExerciseMuscle [id=" + id + ", primaryMuscle=" + primaryMuscle
				+ ", exercise=" + exercise + ", muscle=" + muscle + "]";
	}


	
}
